package codingforgreat.lchot150;

public class Lc287 {
    public int findDuplicate(int[] nums) {
        if(nums == null || nums.length < 2){
            return -1;
        }
        int fast = nums[nums[0]];
        int slow = nums[0];
        while(slow != fast){
            fast = nums[nums[fast]];
            slow = nums[slow];
        }
        fast = 0;
        while(slow != fast){
            fast = nums[fast];
            slow = nums[slow];
        }
        return slow;
    }
}
